package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemMysignupBinding;
import com.sgb.kjwl.model.entity.enterprise.MyNeedQuoteListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.ArrayList;
import java.util.List;


public class MySignUpListAdpater extends BaseRecycleAdapter<MyNeedQuoteListEntity> {
    RequestOptions options = new RequestOptions().placeholder(R.mipmap.icon_default_company)//图片加载出来前，显示的图片
            .fallback(R.mipmap.icon_default_company) //url为空的时候,显示的图片
            .error(R.mipmap.icon_default_company);//图片加载失败后，显示的图片

    RequestOptions personOptions = new RequestOptions().placeholder(R.mipmap.morentu_person)//图片加载出来前，显示的图片
            .fallback(R.mipmap.morentu_person) //url为空的时候,显示的图片
            .error(R.mipmap.morentu_person);//图片加载失败后，显示的图片

    RequestOptions teamOptions = new RequestOptions().placeholder(R.mipmap.icon_default_team)//图片加载出来前，显示的图片
            .fallback(R.mipmap.icon_default_team) //url为空的时候,显示的图片
            .error(R.mipmap.icon_default_team);//图片加载失败后，显示的图片


    public MySignUpListAdpater(Context context) {
        super(context, R.layout.item_mysignup, new ArrayList<>());
    }

    public void setDatasList(List<MyNeedQuoteListEntity> objectList) {
        this.datas = objectList;
        notifyDataSetChanged();
    }

    public void AddDatasList(List<MyNeedQuoteListEntity> ObjectList) {
        this.datas.addAll(ObjectList);
        notifyDataSetChanged();
    }


    @Override
    public void convert(ItemViewHolder holder, MyNeedQuoteListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemMysignupBinding itemBinding = (ItemMysignupBinding) holder.getmBinding();
        itemBinding.llCompanyNameForNeed.setOnClickListener(view -> {
            if (onClickName != null) {
                onClickName.click(entity.getPublishType(), entity.getUserNo(), entity.getTeamNo(), entity.getCompanyNo());
            }
        });
        if (entity.getStatus() == 1) {
            Glide.with(context).load(R.mipmap.icon_baojiazhong).into(itemBinding.imageStateBaojia);
        } else if (entity.getStatus() == 2) {//报价成功
            Glide.with(context).load(R.mipmap.icon_baojiachenggong).into(itemBinding.imageStateBaojia);
        } else if (entity.getStatus() == 3) {//报价失败
            Glide.with(context).load(R.mipmap.icon_baojiashibai).into(itemBinding.imageStateBaojia);
        }
        if (entity.getPublishType() == 1) {
            itemBinding.rivNeedLogo.setVisibility(View.GONE);
            itemBinding.ivNeedItemLogo.setVisibility(View.VISIBLE);
            Glide.with(context).load(entity.getImage()).apply(options).into(itemBinding.ivNeedItemLogo);
        } else if (entity.getPublishType() == 2) {
            itemBinding.rivNeedLogo.setVisibility(View.VISIBLE);
            itemBinding.ivNeedItemLogo.setVisibility(View.GONE);
            Glide.with(context).load(entity.getImage()).apply(teamOptions).into(itemBinding.rivNeedLogo);
        } else {
            itemBinding.rivNeedLogo.setVisibility(View.VISIBLE);
            itemBinding.ivNeedItemLogo.setVisibility(View.GONE);
            Glide.with(context).load(entity.getImage()).apply(personOptions).into(itemBinding.rivNeedLogo);
        }

        switch (entity.getRequirementTypes()) {
            case "1":
                itemBinding.tvNeedType.setText("商标需求");
                break;
            case "2":
                itemBinding.tvNeedType.setText("专利需求");
                break;
            case "3":
                itemBinding.tvNeedType.setText("版权需求");
                break;
            case "4":
                itemBinding.tvNeedType.setText("公司需求");
                break;
            case "5":
                itemBinding.tvNeedType.setText("服务需求");
                break;
            case "6":
                itemBinding.tvNeedType.setText("资产需求");
                break;
        }

        String companyName = entity.getRealName();
        if (entity.getRealName().length() > 12) {
            companyName = entity.getRealName().substring(0, 12) + "...";
        }
        itemBinding.tvCompanyName.setText(companyName);
    }


    private OnClickName onClickName;

    public interface OnClickName {
        void click(int publishType, String userNo, String teamNo, String companyNo);
    }

    public void onClickName(OnClickName onClickName) {
        this.onClickName = onClickName;
    }
}
